(function (angular) {
    'use strict';


    var module = angular.module('sinbad.router', ['ui.router']);//引入了ui-router

    module.config(['$stateProvider', '$urlRouterProvider',
        function ($stateProvider, $urlRouterProvider) {
            $stateProvider.state('main', {
                abstract: true,
                url: '/main',
                views: {
                    '': {
                        templateUrl: 'views/main.html',
                        controller: 'MainCtrl'
                    },
                    'top': {
                        templateUrl: 'views/top/top.html',
                        controller: 'TopCtrl'
                    },
                    'campaigns': {
                        templateUrl: 'views/campaigns/campaigns.html',
                        controller: 'CampCtrl'
                    },
                    'header': {
                        templateUrl: 'views/header/header.html'
                    },
                    'footer': {
                        templateUrl: 'views/footer/footer.html'
                    }
                }
            });

            $stateProvider.state('main.all', {
                url: '/all',
                views: {
                    'account_fee': {
                        templateUrl: 'views/main/account_fee.html'
                    },
                    'trend': {
                        templateUrl: 'views/main/trend.html',
                        controller: 'main.TrendCtrl'
                    },
                    'campaigns': {
                        templateUrl: 'views/main/campaigns.html',
                        controller: 'CampaignsCtrl'
                    },
                    'chart': {
                        templateUrl: 'views/main/chart.html',
                        controller: 'TotalChartCtrl'
                    },
                    'messages': {
                        templateUrl: 'views/main/messages.html'
                    },
                    'planpage': {
                        templateUrl: 'views/planpage/planpage.html',
                        controller: 'PlanpageCtrl'
                    }
                }
            });

            $stateProvider.state('main.all.trend', {
                url: '/trend',
                views: {
                    'trend@main': {
                        templateUrl: 'views/main/trend1.html'
                    }
                }
            });

            $stateProvider.state('campaigns', {
                abstract: true,
                url: '/campaigns',
                views: {
                    '': {
                        templateUrl: 'views/campaign.html'
                    },
                    'header': {
                        templateUrl: 'views/header/header.html'
                    },
                    'footer': {
                        templateUrl: 'views/footer/footer.html'
                    }
                }
            });

            $stateProvider.state('campaigns.campaign', {
                url: '/{campaignID}',
                views: {
                    'info': {
                        templateUrl: 'views/campaign/info.html'
                    },
                    'detail': {
                        templateUrl: 'views/campaign/detail.html',
                        controller: ['$stateParams', '$state', function ($stateParams, $state) {
                            console.log('$stateParams', $stateParams);
                            $state.go('campaigns.campaign.products', {campaignID: $stateParams.campaignID});
                        }]
                    }
                }
            });
            $stateProvider.state('campaigns.campaign.products', {
                url: '/products',
                views: {
                    'products': {
                        templateUrl: 'views/campaign/products.html'
                    }
                }
            });

            $stateProvider.state('about', {
                url: '/about',
                templateUrl: 'views/about.html',
                controller: 'AboutCtrl'
            });

            $stateProvider.state('semiautos', {
                abstract: true,
                url: '/semiautos',
                views: {
                    '': {
                        templateUrl: 'views/semiautos.html'
                    },
                    'header': {
                        templateUrl: 'views/header/header.html'
                    },
                    'footer': {
                        templateUrl: 'views/footer/footer.html'
                    }
                }
            });

            $stateProvider.state('semiautos.ideas', {
                url: '/all',
                views: {
                    'my-semiautos': {
                        templateUrl: 'views/semiautos/my-semiautos.html',
                        controller: 'SemiautosCtrl'
                    },
                    'platform-semiautos': {
                        templateUrl: 'views/semiautos/platform-semiautos.html',
                        controller: 'PlatformSemiautosCtrl'
                    }
                }
            });

            $stateProvider.state('promote', {
                abstract: true,
                url: '/promote',
                views: {
                    '': {
                        templateUrl: 'views/promote.html'
                    },
                    'header': {
                        templateUrl: 'views/header/header.html'
                    },
                    'footer': {
                        templateUrl: 'views/footer/footer.html'
                    }
                }
            });

            $stateProvider.state('promote.ideas', {
                url: '/all',
                abstract: true,
                views: {
                    'promote_header': {
                        templateUrl: 'views/promote/promote_header.html',
                        controller: 'ProheaderChartCtrl'
                    },
                    'promote_body': {
                        templateUrl: 'views/promote/promote_body.html',
                        controller: 'ProbodyChartCtrl'
                    },
                    'promote_tab': {
                        templateUrl: 'views/promote/promote_tab.html',
                        controller: 'ProtabCharCrtl'
                    }
                }
            });

            $stateProvider.state('promote.ideas.creative', {
                url: '/creative',
                views: {
                    'promote_tabs': {
                        templateUrl: 'views/promote/promote_creative.html',
                        controller: 'ProcreChartCtrl'
                    }
                }
            });

            $stateProvider.state('promote.ideas.keyword', {
                url: '/keyword',
                views: {
                    'promote_tabs': {
                        templateUrl: 'views/promote/promote_keyword.html',
                        controller: 'ProkeyChartCtrl'
                    }
                }
            });

            $stateProvider.state('promote.ideas.crowd', {
                url: '/crowd',
                views: {
                    'promote_tabs': {
                        templateUrl: 'views/promote/promote_crowd.html',
                        controller: 'ProcrowdChartCtrl'
                    }
                }
            });


            $stateProvider.state('planpage', {
                abstract: true,
                url: '/planpage',
                views: {
                    '': {
                        templateUrl: 'views/planpage.html'
                    },
                    'header': {
                        templateUrl: 'views/header/header.html'
                    },
                    'footer': {
                        templateUrl: 'views/footer/footer.html'
                    }
                }
            });

            $stateProvider.state('planpage.ideas', {
                url: '/all',
                views: {
                    'planpage': {
                        templateUrl: 'views/planpage/planpage.html',
                        controller: 'PlanpageCtrl'

                    },
                    'planpage_new': {
                        templateUrl: 'views/planpage/planpage_new.html',
                        controller: 'PlanpageNewCtrl'
                    },
                    'planpage_platform': {
                        templateUrl: 'views/planpage/planpage_platform.html',
                        controller: 'PlanpagePlatformCtrl'
                    },
                    'planpage_time': {
                        templateUrl: 'views/planpage/planpage_time.html',
                        controller: 'PlanpageTimeCtrl'
                    },
                    'planpage_regional': {
                        templateUrl: 'views/planpage/planpage_regional.html',
                        controller: 'PlanpageRegionalCtrl'
                    },
                    'planpage_tab': {
                        templateUrl: 'views/planpage/planpage_tab.html',
                        controller: 'PlanpageTabCtrl'
                    },
                    'planpage_shi': {
                        templateUrl: 'views/planpage/planpage_shi.html',
                        controller:'PlanpageShiCtrl'
                    }
                }
            });
            $urlRouterProvider.when('/planpage', '/planpage/all');
            $urlRouterProvider.when('/main', '/main/all');
            $urlRouterProvider.when('/semiautos', '/semiautos/all');
            $urlRouterProvider.when('/promote', '/promote/all/creative');
            $urlRouterProvider.when('/promote/all', '/promote/all/creative');
            $urlRouterProvider.otherwise('/main/all');//和ngRoute的otherwise()函数相似，在用户提交的路径没有被定义的时候它将重定向到指定的页面。函数会在没有任何路径被匹配的时候被运行。
        }
    ]);

})(angular);